package com.cat.slidingWindow;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/grumpy-bookstore-owner/\
 * @create 2025/9/16 11:05
 * @since JDK17
 */

public class Solution30 {
    public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
        int n = customers.length, sum = 0, ans = 0, h = 0;
        for (int i = 0; i < n; i++) {
            if (grumpy[i] == 0) {
                customers[i] *= -1;
            }
            ans += customers[i];
        }
        for (int l = 0, r = 0; r < n; ) {
            while (r - l < minutes) {   //
                sum += Math.min(0, customers[r++]);
            }
            if (r - l == minutes) {
                h = Math.min(sum, h);
                sum -= Math.min(0, customers[l++]);
            }
        }

        return ans - h;
    }
}
